package root.electronclass.electronclass.common.util

import android.app.smdt.SmdtManager
import android.content.Context
import root.electronclass.electronclass.mvp.GlobalParameter
import com.hikvision.dmb.time.InfoTimeApi
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.Date

/**
 *@ClassName TODO
 *@Description TODO
 *@Author caofc
 *@Date 2023/10/12 20:16
 */
class DeviceType {

    companion object {

        /**
         * 卡尔定时开关机
         *
         * @param context
         */
        fun KE_OFF_ON(context: Context) {
            val smdt: SmdtManager? = SmdtManager.create(context)
            if (GlobalParameter.getEcardInfo().powerTime != null && GlobalParameter.getEcardInfo().powerTime.powerOffTime != null && !GlobalParameter.getEcardInfo().powerTime.powerOffTime.equals(
                            "")) {
                val offTime: List<String> = GlobalParameter.getEcardInfo().powerTime.powerOffTime.orEmpty().split(":")
                val onTime: List<String> = GlobalParameter.getEcardInfo().powerTime.powerOnTime.orEmpty().split(":")
                val mOffTime = offTime[0] + ":" + offTime[1]
                val mOnTime = onTime[0] + ":" + onTime[1]
                if (smdt != null) {
                    smdt.smdtSetTimingSwitchMachine(mOffTime, mOnTime, 1.toString())
                } else {
                    ToastUtil.showToast(context, "定时开关机设定失败")
                }
            }

        }

        fun HK_OFF_ON(){
            if (GlobalParameter.getEcardInfo().powerTime != null && GlobalParameter.getEcardInfo().powerTime.powerOffTime != null && !GlobalParameter.getEcardInfo().powerTime.powerOffTime.equals(
                    ""
                )
            ) {
                val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                var dateOnTime: Date? = null
                var dateOffTime: Date? = null
                try {
                    dateOffTime =
                        sdf.parse(DateUtils.getNowDate(DateUtils.DatePattern.ONLY_DAY) + " " + GlobalParameter.getEcardInfo().powerTime.powerOffTime)
                    dateOnTime =
                        sdf.parse(DateUtils.tomorrow() + " " + GlobalParameter.getEcardInfo().powerTime.powerOnTime)
                } catch (e: ParseException) {
                    e.printStackTrace()
                }
                InfoTimeApi.setTimeSwitch(dateOffTime!!.time, dateOnTime!!.time)
            }
        }

    }

}